﻿<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY nbsp "&#x00A0;">
]>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:Locator="urn:Locator"
  exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Locator ">


  <xsl:output method="html" omit-xml-declaration="yes"/>

  <xsl:param name="currentPage"/>

  <xsl:variable name="numberOfResults" select="10"/>

  <xsl:variable name="radius">
    <xsl:choose>
      <xsl:when test="umbraco.library:Request('radius') != '' and umbraco.library:Request('radius') != '0'">
        <xsl:value-of select="number(umbraco.library:Request('radius'))"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="1000000"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:template match="/">


    <xsl:choose>

      <xsl:when test="count(/root//* [@isDoc and string-length(./distance) &gt; 0 and number(./distance) &lt; $radius]) = 0">
        <p>No Results found</p>
      </xsl:when>

      <xsl:otherwise>
        <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key={Locator:GetGoogleMapsKey()}"
                    type="text/javascript"></script>




        <div id="map_canvas" style="width: 780px; height: 400px"></div>

        <h2>
          Top <xsl:value-of select="$numberOfResults"/> results near <xsl:value-of select="umbraco.library:Request('s')"/>
          <xsl:if test="$radius != 1000000">
            (within <xsl:value-of select="$radius"/>&nbsp;<xsl:value-of select="/root/location/@unit"/>)
          </xsl:if>
        </h2>

        <ol>
          <xsl:for-each select="/root//* [@isDoc and string-length(./distance) &gt; 0 and number(./distance) &lt; $radius]">
            <xsl:sort select="./distance" data-type="number"/>
            <xsl:if test="position() &lt;= $numberOfResults">
              <li>
                <strong>
                  <a href="javascript:GEvent.trigger(marker{@id},'click');">
                    <xsl:value-of select="@nodeName"/>
                  </a>
                </strong>
                &nbsp;<xsl:value-of select="round(./distance)"/>
                &nbsp;<xsl:value-of select="/root/location/@unit"/>
              </li>
            </xsl:if>
          </xsl:for-each>
        </ol>


        <xsl:text disable-output-escaping="yes">
    <![CDATA[

        <script type="text/javascript">
        

          if (GBrowserIsCompatible()) {


      var yellowIcon = new GIcon();
      yellowIcon.image = "http://esa.ilmari.googlepages.com/markeryellow.png";
      yellowIcon.iconSize = new GSize(20, 34);
      yellowIcon.iconAnchor = new GPoint(9, 34);


            var map = new GMap2(document.getElementById("map_canvas"));
      map.addControl(new GSmallMapControl());

    ]]>
    </xsl:text>
        map.setCenter(new GLatLng(<xsl:value-of select="/root/location"/>), 6);

        map.addOverlay(new GMarker(new GLatLng(<xsl:value-of select="/root/location"/>),{clickable:false, icon:yellowIcon})); // visited

        <xsl:for-each select="/root//* [@isDoc and string-length(./distance) &gt; 0 and number(./distance) &lt; $radius]">
          <xsl:sort select="./distance" data-type="number"/>
          <xsl:if test="position() &lt;= $numberOfResults">
            var latlng<xsl:value-of select="@id"/> = new GLatLng(<xsl:value-of select="./location"/>);
            var marker<xsl:value-of select="@id"/> = new GMarker(latlng<xsl:value-of select="@id"/>)

            GEvent.addListener(marker<xsl:value-of select="@id"/>, "click", function() {
            var myHtml = "<b>" + "<xsl:value-of select="@nodeName"/>" + "</b><br/>";

            <xsl:text disable-output-escaping="yes">
      <![CDATA[
      myHtml += "<a href=']]></xsl:text><xsl:value-of select="umbraco.library:NiceUrl(@id)"/><xsl:text disable-output-escaping="yes"><![CDATA['>details</a>";
      ]]>
      </xsl:text>
            map.openInfoWindowHtml(latlng<xsl:value-of select="@id"/>, myHtml);
            });


            map.addOverlay(marker<xsl:value-of select="@id"/>);

          </xsl:if>
        </xsl:for-each>

        <xsl:text disable-output-escaping="yes">
      <![CDATA[     
            }


          </script>
      ]]>
      </xsl:text>


      </xsl:otherwise>
    </xsl:choose>




  </xsl:template>

</xsl:stylesheet>